package acwing.二分;

import java.io.*;




/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/20
 */
public class 机器人跳跃问题 {

    static int n;

    static final int N = 100010;
    static int[] h = new int[N];

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    public static boolean check(int e)
    {
        for (int i = 1; i <= n; i ++ )
        {
            e = e * 2 - h[i];
            if (e >= 100000) return true;
            if (e < 0) return false;
        }
        return true;
    }

    public static void main(String[] args) throws IOException
    {
        n = Integer.parseInt(in.readLine());

        String[] data = in.readLine().split(" ");
        for (int i = 1; i <= n; i ++ )
            h[i] = Integer.parseInt(data[i - 1]);

        int l = 0, r = 100000;
        while (l < r)
        {
            int mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }

        System.out.println(r);
        in.close();
    }
}
